package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo14 {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();){
            conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED);
            conn.setAutoCommit(false);
            String sql = "INSERT INTO userinfo(username,password,nickname,age)" +
                         "VALUES (?,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,"赵六");
            ps.setString(2,"666");
            ps.setString(3,"老赵");
            ps.setInt(4,23);
            int num = ps.executeUpdate();
            System.out.println(num>0?"添加成功":"添加失败");
            conn.commit();
//            conn.rollback();

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
